package cn.dankal.lequ.ui.fragment.comprehensive_fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.dankal.lequ.R;
import cn.dankal.lequ.commom.adapter.BaseAdapter.ViewHolder;
import cn.dankal.lequ.commom.adapter.BaseAdapter.recyclerview.CommonAdapter;
import cn.dankal.lequ.commom.adapter.BaseAdapter.recyclerview.MultiItemCommonAdapter;
import cn.dankal.lequ.commom.adapter.BaseAdapter.recyclerview.MultiItemTypeSupport;

/**
 * Created by 苏彬 on 2016/4/16.
 */
public class YoulikeFragment extends Fragment {

    @Bind(R.id.recyclerview)
    RecyclerView id_home_tab_recyclerview;
    LinearLayoutManager linearLayoutManager;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.recyclerview, container, false);
        ButterKnife.bind(this, view);
        return view;
    }


    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initRecyclerView();
    }

    private void initRecyclerView() {
        linearLayoutManager = new LinearLayoutManager(getActivity());
        id_home_tab_recyclerview.setLayoutManager(linearLayoutManager);
        id_home_tab_recyclerview.setHasFixedSize(true);
        final List<Integer> mDatas32 = new ArrayList<>();
        mDatas32.add(1);
        mDatas32.add(2);
        mDatas32.add(3);
        mDatas32.add(4);
        final List<String> mDatas1 = new ArrayList<>();
        mDatas1.add("1");
        mDatas1.add("2");
        mDatas1.add("3");
        mDatas1.add("4");
        mDatas1.add("5");
        final List<String> mData = new ArrayList<>();
        mData.add("1");
        mData.add("2");
        mData.add("3");
        mData.add("4");
        mData.add("5");
        mData.add("6");
        mData.add("7");
        final MultiItemTypeSupport<String> modelMultiItemTypeSupport = new MultiItemTypeSupport<String>() {
            @Override
            public int getLayoutId(int itemType) {
                if (itemType == 0) {
                    return R.layout.item_currency_game;
                } else if (itemType == 1) {
                    return R.layout.item_check_more;
                } else {
                    return R.layout.item_currency_game;
                }
            }

            @Override
            public int getItemViewType(int position, String s) {
                if (mDatas1.size() <= 5) {
                    if (position == 4) {
                        return 1;
                    } else {
                        return 0;
                    }
                } else {
                    return 0;
                }
            }
        };

        id_home_tab_recyclerview.setAdapter(new CommonAdapter<Integer>(getActivity(), R.layout.item_youlike, mDatas32) {
            @Override
            public void convert(ViewHolder holder, final Integer integer) {
                final RecyclerView recyclerView = holder.getView(R.id.rv_classify);
                linearLayoutManager = new LinearLayoutManager(getActivity());
                recyclerView.setLayoutManager(linearLayoutManager);
                recyclerView.setHasFixedSize(true);
                recyclerView.setAdapter(new MultiItemCommonAdapter<String>(getActivity(), mDatas1, modelMultiItemTypeSupport) {
                    @Override
                    public void convert(ViewHolder holder, final String s) {
                        if (holder.getLayoutId() == R.layout.item_check_more) {
                            holder.setOnClickListener(R.id.all_check_more, new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    if (integer == 1) {
                                        mDatas1.clear();
                                        for (int i = 0; i < mData.size(); i++) {
                                            mDatas1.add(mData.get(i));
                                        }
                                        recyclerView.getAdapter().notifyDataSetChanged();
//                                        updateDatas(mDatas1);
                                    }
                                }
                            });
                        }
                    }
                });
            }

        });
    }
}
